import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from "@/components/layout/index.vue" //模版

Vue.use(VueRouter)

const routes = [{
	path: '/login', //登录页
	alias: "/",
	name:"login",
	meta: {
		requiresAuth: true
	},
	component: () => import("@/pages/Login/Login.vue")
},
{
	path: '/register', //注册页
	name:"register",
	meta: {
		requiresAuth: true
	},
	component: () => import("@/pages/Register/Register.vue")
},
{
	path: '/main', //主要内容区域
	name:"main",
	component: layout,
	children: [{
		path: '/home', //首页
		name:"home",
		alias: "/",
		component: () => import("@/pages/Home/Home.vue")
	},
	{
		path: '/signup', //报名页
		name:"signup",
		component: () => import("@/pages/SignUp/SignUp.vue")
	}, {
		path: '/signupForm', //报名表
		name:"signupForm",
		props:(route)=>{
			return {
				eid:route.query.eid
			}
		},
		component: () => import("@/pages/SignUpForm/SignUpForm.vue")
	}, {
		path: '/signupFormDetails', //报名表详情页
		name:"signupFormDetails",
		props:(route)=>{
			return {
				eid:route.query.eid,
				id:route.query.id
			}
		},
		component: () => import("@/pages/SignUpFormDetails/SignUpFormDetails.vue")
	}, {
		path: '/details', //详情页
		name:"details",
		props:(route)=>{
			return {
				id:route.query.id
			}
		},
		component: () => import("@/pages/Details/Details.vue")
	}, {
		path: '/certificate', //证书
		name:"certificate",
		component: () => import("@/pages/Certificate/Certificate.vue")
	}, {
		path: '/user', //用户中心
		name:"user",
		component: () => import("@/pages/User/User.vue")
	},{
		path: '/pay', //支付
		name:"pay",
		props:(route)=>{
			return {
				id:route.query.id
			}
		},
		component: () => import("@/pages/Pay/Pay.vue")
	}]
},
{
	path: '*',
	name:"404",
	meta: {
		requiresAuth: true
	},
	component: () => import("@/pages/NotFound/NotFound.vue")
},
]

const router = new VueRouter({
	mode: 'history',
	routes
})

// 路由拦截
// router.beforeEach((to,from,next)=>{
//   if(!to.matched.some(record => record.meta.requiresAuth)){//是否需要拦截
//     const token = localStorage.getItem("token")
//     if(token){//是否有token
//       next()
//     }else{
//       next({path:"/login"})
//     }
//   }else{
//     next()
//   }
// })

export default router
